// may be building a C lib for a plugin
let layout = cx.layout(KindTarget);
let output = layout.native(pkg);
+ let old_output = layout.proxy().old_native(pkg);
let mut p = process(cmd.next().unwrap(), pkg, cx)
.env("OUT_DIR", Some(&output))
.env("DEPS_DIR", Some(&output))
}
Ok(proc() {
if first {
- try!(fs::mkdir(&output, UserRWX).chain_error(|| {
+ try!(if old_output.exists() {
+ fs::rename(&old_output, &output)
+ } else {
+ fs::mkdir(&output, UserRWX)
+ }.chain_error(|| {
internal("failed to create output directory for build command")
}));
}
{fresh} foo v0.0.0 ({url})
", fresh = FRESH, url = foo.url())));
})
+
+test!(rebuild_preserves_out_dir {
+ let mut build = project("builder");
+ build = build
+ .file("Cargo.toml", r#"
+ [package]
+ name = "build"
+ version = "0.5.0"
+ authors = ["wycats@example.com"]
+ "#)
+ .file("src/main.rs", r#"
+ use std::os;
+ use std::io::File;
+
+ fn main() {{
+ let path = Path::new(os::getenv("OUT_DIR").unwrap()).join("foo");
+ if os::getenv("FIRST").is_some() {
+ File::create(&path).unwrap();
+ } else {
+ File::create(&path).unwrap();
+ }
+ }}
+ "#);
+ assert_that(build.cargo_process("cargo-build"), execs().with_status(0));
+
+ let foo = project("foo")
+ .file("Cargo.toml", format!(r#"
+ [package]
+ name = "foo"
+ version = "0.0.0"
+ authors = []
+ build = '{}'
+ "#, build.bin("build").display()).as_slice())
+ .file("src/lib.rs", "pub fn bar() -> int { 1 }");
+ foo.build();
+ foo.root().move_into_the_past().assert();
+
+ assert_that(foo.process(cargo_dir().join("cargo-build"))
+ .env("FIRST", Some("1")),
+ execs().with_status(0)
+ .with_stdout(format!("\
+{compiling} foo v0.0.0 ({url})
+", compiling = COMPILING, url = foo.url())));
+
+ File::create(&foo.root().join("src/bar.rs")).assert();
+ assert_that(foo.process(cargo_dir().join("cargo-build")),
+ execs().with_status(0)
+ .with_stdout(format!("\
+{compiling} foo v0.0.0 ({url})
+", compiling = COMPILING, url = foo.url())));
+})